Page({
data: {
        one:"",
        two:"",
        maxTextLen:10
},
onLoad: function (options) {
        wx.setNavigationBarTitle({
                title: '注册'
                })
},

gou(e){
        this.setData({
                one:e.detail.value
        })
        console.log(this.data.one)
},
dan(e){
        this.setData({
                two:e.detail.value
        })
        console.log(this.data.two)
        if(this.data.one == this.data.two){
                this.setData({
                        xianshi:false
                })
        }else{
                this.setData({
                        xianshi:true
                })
        }
},
huoqu_data(e){
        var my_name = e.detail.value.my_name
        var my_id = e.detail.value.my_id
        var my_pwd = e.detail.value.my_pwd
        var my_img = "1"
        console.log(my_name)
        console.log(my_id)
        console.log(my_pwd)
        console.log(my_img)
        if(my_name == "" || my_id == "" ||  my_pwd == ""){
                wx.showToast({
                        title: '输入有误，重新输入',
                        icon: 'none',
                        duration: 2000,//持续的时间
                })           
        } else(
        wx.request({
                url: 'http://localhost:3000/add_user',
                method:'POST',
                data:{
                        data : e.detail.value,
                        img:my_img
                },
                success: (res)=> {
                        console.log(res.data)
                        if(res.data == "该账号已存在"){
                                wx.showToast({
                                        title: '改账号已被注册，请重新输入',
                                        icon: 'none',
                                        duration: 1000,
                                })
                        } else if(res.data == "可以注册"){
                                console.log("注册成功")
                                wx.showModal({  
                                title: '注册成功',  
                                content: '请返回登录！',  
                                success: function(res) {  
                                        if (res.confirm) {  
                                        console.log('用户点击确定')  
                                        wx.navigateTo({
                                        url: '../../login/login',
                                        })
                                        } else if (res.cancel) {  
                                        wx.navigateTo({
                                        url: '../../login/login',
                                        }) 
                                        }  
                                }  
                        })     
                        }
                }
                })
        )
},
})


